package com.yanchangapp.ui.activity.base;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;

import com.yanchangapp.ui.activity._n_manage.CalendarRangeActivity;
import com.yanchangapp.ui.activity._n_manage.HistoryPlanActivity;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.widget.JumpTextView;
import com.yanchangapp.R;
import com.yanchangapp.model.cache.UserCache;

import butterknife.BindView;

/**
 * @author crazyZhangxl on 2018-11-16 8:15:09.
 * Describe: 闪屏页
 *
 * 已登陆  --  首页
 *   否则  --  登录页
 *
 */

public class SplashActivity extends BaseActivity {
    @BindView(R.id.jumpTextView)
    JumpTextView mJumpTextView;

    @Override
    protected void init() {

    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_splash;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }
        mJumpTextView.setDrawingState(true);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        mJumpTextView.setMyViewClickListener(new JumpTextView.MyViewClickListener() {

            @Override
            public void onJumpOnclick() {
                mJumpTextView.doAnimatorStop();
            }

            @Override
            public void onJumpEnd() {
                doJump();
            }
        });
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK){
            if (mJumpTextView != null && mJumpTextView.isProgressRunning){
                return false;
            }
        }
        return super.onKeyDown(keyCode, event);

    }

    private void  doJump(){
        if (TextUtils.isEmpty(UserCache.getAuthorization())){
            jumpToActivity(LoginActivity.class);
        }else {
            jumpToActivity(MainActivity.class);
        }
        SplashActivity.this.finish();
    }

}
